<link rel="stylesheet" href="<?php echo base_url() ?>css/jquery.ui.all.min.css">
<script src="<?php echo base_url() ?>js/external/jquery.bgiframe-2.1.2.js"></script>
<script src="<?php echo base_url() ?>js/ui/jquery.ui.core.min.js"></script>
<script src="<?php echo base_url() ?>js/ui/jquery.ui.widget.min.js"></script>
<script src="<?php echo base_url() ?>js/ui/jquery.ui.mouse.min.js"></script>
<script src="<?php echo base_url() ?>js/ui/jquery.ui.button.min.js"></script>
<script src="<?php echo base_url() ?>js/ui/jquery.ui.draggable.min.js"></script>
<script src="<?php echo base_url() ?>js/ui/jquery.ui.position.min.js"></script>
<script src="<?php echo base_url() ?>js/ui/jquery.ui.dialog.min.js"></script>
<script>
    $(function() {
        $( "#dialog-confirm" ).dialog({
            resizable: false,
            height:600,
            width:600,
            modal: true,
            buttons: {
                "Benar": function() {
                    document.form_daftar_new.submit();
                },
                "Salah": function() {
                    $( this ).dialog( "close" );
                }
            },
            autoOpen : false
        });
    });    
    function check_nocic(){

        nama = $('.nama').val();
        nohp = $('.nohp').val();
        gol = $('.gol').val();
        kelas = $('.kelas').val();
        if(nama==''){
            alert('Harap isi nama!!');
        }else if(nohp==''){
            alert('Harap isi no HP!!');
        }else if(gol==-1){
            alert('Harap pilih golongan peserta');
        }else if(kelas==-1){
            alert('Harap pilih kelas pelatihan');
        }else{
            //cek nama
            if(nama!='' && nohp!=''){
                data_post = {cari_nama : nama, cari_nohp : nohp};
                $.ajax({
                    type : 'POST',
                    data: data_post,
                    url : '<?php echo base_url() ?>pendaftaran/daftar_con/check_exist',
                    dataType:'json',
                    success : function(data){
                        if(data['respon']['cond']){
                            alert('No telp tersebut sudah ada!! Jika sudah pernah mendaftar, gunakan fitur search untuk mencari user tersebut');
                        }else{
                            data_post = {no_cic : $('#nocic').val()};
                            if($('#nocic').val()==''){
                                //document.form_daftar_new.submit();
                                open_confirm(false);
                            }else{
                                $.ajax({
                                    type : 'POST',
                                    data: data_post,
                                    url : '<?php echo base_url() ?>pendaftaran/daftar_con/check_no_cic',
                                    dataType:'json',
                                    success : function(data){
                                        if(data['respon']){
                                            //document.form_daftar_new.submit();
                                            open_confirm(true);
                                        }else{
                                            alert('No CIC yang anda masukkan sudah tidak dapat digunakan lagi untuk term ini');
                                        }
                                    }
                                });
                            }
                        }
                    }
                });
            }
        }
    }

    function open_confirm(is_cic){
        nama = $('.nama').val();
        nohp = $('.nohp').val();
        list_diskon = '';
        
            if(!is_cic){
                values = $('input:checkbox:checked.groupdiskon').map(function () {
                    return this.value;
                }).get();
                $.ajax({
                    type : 'POST',
                    data: {str : JSON.stringify(values)},
                    url : '<?php echo base_url() ?>pendaftaran/daftar_con/get_nama_diskon',
                    dataType:'html',
                    success : function(data){
                        list_diskon=data
                    }
                }).then(function(){
                    switch($('.gol').val()){
                        case '1' : 
                            text_gol = "[1] Mahasiswa S1 ITB";
                            break
                        case '2' :
                            text_gol = "[2] Mahasiswa S2/S3/Alumni ITB";
                            break
                        case '3' : 
                            text_gol = "[3] Pelajar dan Mahasiswa non ITB";
                            break
                        case '4' :
                            text_gol = "[4] Umum";
                            break
                        case '5' : 
                            text_gol = "[5] Staff ITB";
                            break
                        case '6' :
                            text_gol = "[6] Internal ComLabs";
                            break
                        default :
                            text_gol = "Fail";
                            break
                    }

                    kelas = $('.kelas').val();

                    $("#konfirm_nama").text(nama);
                    $("#konfirm_nohp").text(nohp);
                    $("#konfirm_gol").text(text_gol);
                    $("#konfirm_kelas").text(kelas);
                    $("#konfirm_diskon").html(list_diskon);
                    $( "#dialog-confirm" ).dialog('open');
                });
            }else{
                list_diskon = 'Diskon CIC Card';
                switch($('.gol').val()){
                    case '1' : 
                        text_gol = "[1] Mahasiswa S1 ITB";
                        break
                    case '2' :
                        text_gol = "[2] Mahasiswa S2/S3/Alumni ITB";
                        break
                    case '3' : 
                        text_gol = "[3] Pelajar dan Mahasiswa non ITB";
                        break
                    case '4' :
                        text_gol = "[4] Umum";
                        break
                    case '5' : 
                        text_gol = "[5] Staff ITB";
                        break
                    case '6' :
                        text_gol = "[6] Internal ComLabs";
                        break
                    default :
                        text_gol = "Fail";
                        break
                }

                kelas = $('.kelas').val();

                $("#konfirm_nama").text(nama);
                $("#konfirm_nohp").text(nohp);
                $("#konfirm_gol").text(text_gol);
                $("#konfirm_kelas").text(kelas);
                $("#konfirm_diskon").text(list_diskon);
                $( "#dialog-confirm" ).dialog('open');
            }
    }
</script>    

<div id="dialog-confirm" title="Konfirmasi Data Peserta">

    <table ID="tabel-confirm" width="400" border="0" cellspacing="0" cellpadding="0">
        <tr>
            <td>
                <div>Nama Lengkap :</div>
                <div id="konfirm_nama"></div>
                <br/>
            </td>
        </tr>
        <tr>
            <td>
                <div>No Handphone :</div>
                <div id="konfirm_nohp"></div>
                <br/>
            </td>
        </tr>
        <tr>
            <td>
                <div>Golongan :</div>
                <div id="konfirm_gol"></div>
                <br/>
            </td>
        </tr>
        <tr>
            <td>
                <div>Mendaftar pada Pelatihan :</div>
                <div id="konfirm_kelas"></div>
                <br/>
            </td>
        </tr>
        <tr>
            <td>
                <div>Diskon :</div>
                <div id="konfirm_diskon"></div>
            </td>
        </tr>
    </table>
</div>


<!--ISI MULAI-->
<div class="beftabel">
    <form name="form_daftar_new" action="<?php echo base_url() ?>pendaftaran/daftar_con/daftar_new_proses" method="post">
        <table border="0" cellspacing="0" cellpadding="0">
            <tr>
                <td><table width="400" border="0" cellspacing="0" cellpadding="0">
                        <tr>
                            <td class="namaform">Nama Lengkap</td>
                        </tr>
                        <tr>
                            <td><input name="nama" type="text" class="field1 nama" id="textfield" /></td>
                        </tr>
                        <tr>
                            <td class="namaform">No Handphone</td>
                        </tr>
                        <tr>
                            <td><input  name="nohp" type="text" class="field1 nohp" id="textfield2" /></td>
                        </tr>
                        <tr>
                            <td class="namaform">Golongan [?]</td>
                        </tr>
                        <tr>
                            <td><label for="gol"></label>
                                <select name="gol" class="field2 gol" id="select">
                                    <option value="-1">--- Pilih Golongan ---</option>
                                    <option value="1">[1] Mahasiswa S1 ITB</option>
                                    <option value="2">[2] Mahasiswa S2/S3/Alumni ITB</option>
                                    <option value="3">[3] Pelajar dan Mahasiswa non ITB</option>
                                    <option value="4">[4] Umum</option>
                                    <option value="5">[5] Staff ITB</option>
                                    <option value="6">[6] Internal ComLabs</option>
                                </select></td>
                        </tr>
                        <tr>
                            <td class="namaform">Mendaftar pada Pelatihan</td>
                        </tr>                 
                        <tr>
                            <td>
                                <?php
                                $script = 'class="field2 kelas" id="select"';
                                echo form_dropdown('kelas', $pelatihan, '', $script);
                                ?>
                            </td>
                        </tr> 
                        <tr>
                            <td class="namaform">Diskon yang Diperoleh</td>
                        </tr>                 
                        <tr>
                            <td>
                                <ul class="tabs">
                                    <li><a href="#tab1">Dengan CIC Card</a></li>
                                    <li><a href="#tab2">Tanpa CIC Card</a></li>
                                </ul>
                                <div class="tab_container">
                                    <div id="tab1" class="tab_content">
                                        <input name="nocic" type="text" class="fieldy" id="nocic" />
                                    </div>
                                    <div id="tab2" class="tab_content">
                                        <table width="100%" border="0" cellspacing="0" cellpadding="0">
                                            <?php for ($i = 0; $i < count($diskon); $i++) { ?>
                                                <input class="groupdiskon" id="diskon" type="checkbox" name="diskon[]" value="<?php echo $diskon[$i]['no'] ?>" /><?php echo $diskon[$i]['nama'] ?>
                                                <br/>
                                            <?php } ?>
                                        </table>
                                    </div>
                                </div>
                            </td>
                        </tr>
                    </table>
                </td>
                <td valign="top" class="jarak">&nbsp;</td>
                <td valign="top" class="tempatbutton">
                    <input type="button" class="save" id="button" value="Save" onclick="check_nocic()"/>
                </td>
            </tr>
        </table>
    </form>    
</div>

</div>
</td>
<td class="b6"></td>
</tr>
<tr>
    <td class="b4"></td>
    <td class="b5">    <div class="footer2">Copyright &copy;2011 CIC Team | Credits</div></td>
    <td class="b6"></td>
</tr>
<tr>
    <td id="b7"></td>
    <td id="b8"></td>
    <td id="b9"></td>
</tr>
</table>
